﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Tools.Services.Dtos/BaseLocationInfo 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       BaseLocationInfo
* 创建时间：  2025/5/24 14:49:55
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.Tools.Services.Tools.Dto
{
    /// <summary>
    /// 位置信息
    /// </summary>
    public record BaseLocationInfo
    {
        /// <summary>
        /// 国家
        /// </summary>
        public string? Country { get; init; }
        /// <summary>
        /// 省份
        /// </summary>
        public string? Province { get; init; }

        /// <summary>
        /// 城市
        /// </summary>
        public string? City { get; init; }

        /// <summary>
        /// 网络服务商
        /// </summary>
        public string? Isp { get; init; }

        /// <summary>
        /// 转换地址信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static BaseLocationInfo Parse(string input)
        {
            var parts = input.Split('|');

            if (parts.Length >= 5)
            {
                return new BaseLocationInfo
                {
                    Country = parts[0] != "0" ? parts[0] : "",
                    Province = parts[2] != "0" ? parts[2] : "",
                    City = parts[3] != "0" ? parts[3] : "",
                    Isp = parts[4] != "0" ? parts[4] : "",
                };
            }

            return new BaseLocationInfo();
        }
    }
}
